package project.web.controller;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import fld.background.system.controller.BaseController;
import fld.utils.DataGrid;
import project.background.entity.CompanyInfo;
import project.background.service.ActivityService;
import project.background.service.CompanyInfoService;
import project.background.service.ProductService;
import project.background.service.ProductTypeService;
import project.background.service.TeamMemberService;
import project.background.service.VideoService;

/**
 * web首页-盛煜web
 * @author yc
 * 2019年1月11日
 */
@Controller
@RequestMapping (value="/web/syweb")
public class WebSywebIndexController extends BaseController{
	
	private final static String MODEL_PATH = "web/syweb/";
	
	private final static Long companyId = 9L;
	
	@Autowired
	private CompanyInfoService companyInfoService;
	@Autowired
	private ProductService productService;
	@Autowired
	private ProductTypeService productTypeService;
	@Autowired
	private ActivityService activityService;
	@Autowired
	private TeamMemberService teamMemberService;
	@Autowired
	private VideoService videoService;

	/**
	 * 首页
	 * @return
	 * @author yc
	 * @date 2018年12月9日
	 */
	@RequestMapping(value="index")
	public ModelAndView index(){
		ModelAndView model = new ModelAndView();
		model.setViewName(MODEL_PATH+"index");
		model.addObject("webPage", "index");
		CompanyInfo info = companyInfoService.getNewEstCompanyInfoByCompanyId(companyId);
		model.addObject("companyInfo", null == info ? new HashMap<String,Object>() : info);
		return model;
	}
	
	/**
	 * 简介
	 * @return
	 * @author yc
	 * @date 2018年12月9日
	 */
	@RequestMapping(value="info")
	public ModelAndView info(){
		ModelAndView model = new ModelAndView();
		model.setViewName(MODEL_PATH+"info");
		model.addObject("webPage", "info");
		CompanyInfo info = companyInfoService.getNewEstCompanyInfoByCompanyId(companyId);
		model.addObject("companyInfo", null == info ? new HashMap<String,Object>() : info);
		return model;
	}
	

	/**
	 * 产品
	 * @return
	 * @author yc
	 * @date 2018年12月9日
	 */
	@RequestMapping(value="product")
	public ModelAndView product(){
		ModelAndView model = new ModelAndView();
		model.setViewName(MODEL_PATH+"product");
		model.addObject("webPage", "product");
		Map<String,Object> tmap = new HashMap<String,Object>();
		tmap.put("companyId", companyId);
		model.addObject("productTypes", productTypeService.queryAll(tmap));
		return model;
	}
	
	/**
	 * 查询产品列表
	 * @param tmap
	 * @return
	 * 2019年1月12日
	 * @author yc
	 */
	@ResponseBody
	@RequestMapping(value="productGrid")
	public DataGrid productGrid(@RequestParam Map<String,Object> tmap) {
		tmap.put("companyId", companyId);
		return productService.grid(tmap);
	}
	
	/**
	 * 详情
	 * @return
	 * 2019年1月12日
	 * @author yc
	 */
	@RequestMapping(value="productDetail/{id}")
	public ModelAndView productDetail(@PathVariable("id") Long id){
		ModelAndView model = new ModelAndView();
		model.setViewName(MODEL_PATH+"productDetail");
		model.addObject("webPage", "productDetail");
		model.addObject("productInfo",productService.getInfo(id));
		return model;
	}
	
	/**
	 * 活动
	 * @return
	 * @author yc
	 * @date 2018年12月9日
	 */
	@RequestMapping(value="activity")
	public ModelAndView activity(){
		ModelAndView model = new ModelAndView();
		model.setViewName(MODEL_PATH+"activity");
		model.addObject("webPage", "activity");
		return model;
	}
	
	/**
	 * 查询动态列表
	 * @param tmap
	 * @return
	 * 2019年1月12日
	 * @author yc
	 */
	@ResponseBody
	@RequestMapping(value="activityGrid")
	public DataGrid activityGrid(@RequestParam Map<String,Object> tmap) {
		tmap.put("companyId", companyId);
		return activityService.grid(tmap);
	}
	
	/**
	 * 详情
	 * @return
	 * 2019年1月12日
	 * @author yc
	 */
	@RequestMapping(value="activityDetail/{id}")
	public ModelAndView activityDetail(@PathVariable("id") Long id){
		ModelAndView model = new ModelAndView();
		model.setViewName(MODEL_PATH+"activityDetail");
		model.addObject("webPage", "activityDetail");
		model.addObject("activityInfo", activityService.getInfo(id));
		return model;
	}
	
	/**
	 * 团队
	 * @return
	 * @author yc
	 * @date 2018年12月9日
	 */
	@RequestMapping(value="teamMember")
	public ModelAndView teamMember(){
		ModelAndView model = new ModelAndView();
		model.setViewName(MODEL_PATH+"teamMember");
		model.addObject("webPage", "teamMember");
		return model;
	}
	
	/**
	 * 查询团队成员列表
	 * @param tmap
	 * @return
	 * 2019年1月12日
	 * @author yc
	 */
	@ResponseBody
	@RequestMapping(value="teamMemberGrid")
	public DataGrid teamMemberGrid(@RequestParam Map<String,Object> tmap) {
		tmap.put("companyId", companyId);
		return teamMemberService.grid(tmap);
	}
	
	/**
	 * 详情
	 * @return
	 * 2019年1月12日
	 * @author yc
	 */
	@RequestMapping(value="teamMemberDetail/{id}")
	public ModelAndView teamMemberDetail(@PathVariable("id") Long id){
		ModelAndView model = new ModelAndView();
		model.setViewName(MODEL_PATH+"teamMemberDetail");
		model.addObject("webPage", "teamMemberDetail");
		model.addObject("teamMemberInfo", teamMemberService.getInfo(id));
		return model;
	}
	
	/**
	 * 视频
	 * @return
	 * @author yc
	 * @date 2018年12月9日
	 */
	@RequestMapping(value="video")
	public ModelAndView video(){
		ModelAndView model = new ModelAndView();
		model.setViewName(MODEL_PATH+"video");
		model.addObject("webPage", "video");
		return model;
	}
	
	/**
	 * 查询视频列表
	 * @param tmap
	 * @return
	 * 2019年1月12日
	 * @author yc
	 */
	@ResponseBody
	@RequestMapping(value="videoGrid")
	public DataGrid videoGrid(@RequestParam Map<String,Object> tmap) {
		tmap.put("companyId", companyId);
		return videoService.grid(tmap);
	}
	
	/**
	 * 详情
	 * @return
	 * 2019年1月12日
	 * @author yc
	 */
	@RequestMapping(value="videoDetail/{id}")
	public ModelAndView videoDetail(@PathVariable("id") Long id){
		ModelAndView model = new ModelAndView();
		model.setViewName(MODEL_PATH+"videoDetail");
		model.addObject("webPage", "videoDetail");
		model.addObject("videoInfo", videoService.getInfo(id));
		return model;
	}

	/**
	 * 联系我们
	 * @return
	 * @author yc
	 * @date 2018年12月9日
	 */
	@RequestMapping(value="contact")
	public ModelAndView contact(){
		ModelAndView model = new ModelAndView();
		model.setViewName(MODEL_PATH+"contact");
		model.addObject("webPage", "contact");
		CompanyInfo info = companyInfoService.getNewEstCompanyInfoByCompanyId(companyId);
		model.addObject("companyInfo", null == info ? new HashMap<String,Object>() : info);
		return model;
	}
	
}
